<template>
  <Spin :spinning="loading" tip="Loading...">
  <div>
    <!-- table -->
    <!-- 质量报告查询 - 明细 -->
    <BreakSpace label="质量信息" :containerStyle="{ marginBottom: '10px' }"/>
    <FormPanel ref="formPanel1" :list="formList" :cols="3" :formType="'add'" labelWidth="120" :isSubmitBtn="false"
               @formChange="formChangeHandle"/>
    <BaseDialog :visible.sync="weixiugongdan" :title="'维修工单选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <SelectWeiXiuGongDan @close="weixiugongdanClose" @save="weixiugongdanSave"></SelectWeiXiuGongDan>
    </BaseDialog>
    <BaseDialog :visible.sync="zhusunjian" :title="'主损件选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <Selectzhusunjian @close="zhusunjianClose" @save="zhusunjianSave"></Selectzhusunjian>
    </BaseDialog>
    <BaseDialog :visible.sync="guzhangxianxiangdaima" :title="'故障现象选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <Selectguzhangxianxiang @close="guzhangxianxiangdaimanClose" @save="guzhangxianxiangdaimaSave"></Selectguzhangxianxiang>
    </BaseDialog>
    <BaseDialog :visible.sync="application" :title="'索赔单选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <SelectClaimApplication @close="applicationClose" @save="applicationSave"></SelectClaimApplication>
    </BaseDialog>
    <BaseDialog :visible.sync="peijianhuanxiajianlistaddflag" :title="'配件换下件列表新增'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <Peijianhuanxiajianlist @close="peijianhuanxiajianClose" @save="peijianhuanxiajianSave"></Peijianhuanxiajianlist>
    </BaseDialog>
    <BaseDialog :visible.sync="fault" :title="'诊断仪检测故障码新增'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <Fault @close="faultClose" @save="faultSave"></Fault>
    </BaseDialog>
    <BaseDialog :visible.sync="KeepCarShow" :title="'选择留车单号'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <KeepCar @close="KeepCarClose" @save="KeepCarSave"></KeepCar>
    </BaseDialog>
    <BaseDialog :visible.sync="visible" :title="'车型'" width="850px" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <vehicle @close="chexingClose" @save="chexingsave"></vehicle>
    </BaseDialog>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="故障码列表" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table1"
      :columns="columns"
      :params="fetchParams"
      :datakey="'items'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      :is-select-column="false"
      :isPagination = false
      height="auto"
      selectionType="single"
    ><template slot="controls" slot-scope="props">
      <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="faultAdd()">添加</multiuse-button>
    </template></FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="换下件配件列表" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table2"
      :columns="columns2"
      :params="fetchParams"
      :datakey="'items'"
      :onColumnsChange="columns2 => (this.columns2 = columns2)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :is-select-column="false"
      :isPagination = false
      height="auto"
    > <template slot="controls" slot-scope="props">
      <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="peijianhuanxiajianadd()">添加</multiuse-button>
    </template></FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="历史审核记录" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table3"
      :columns="columns3"
      :params="fetchParams"
      :datakey="'items'"
      :onColumnsChange="columns3 => (this.columns3 = columns3)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :is-select-column="false"
      :isPagination = false
      height="auto"
    ></FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <div
      :style="{
        position: 'fixed',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }">
<!--      <multiuse-button :click="cancels.bind()">作废</multiuse-button>-->
      <multiuse-button type="primary" :click="saveDialog.bind()">保存</multiuse-button>
      <multiuse-button :click="submit.bind()">提交</multiuse-button>
      <multiuse-button type="primary" @click="closeDialog">关 闭</multiuse-button>
    </div>
    <div style="margin-bottom: 4rem;"></div>
  </div>
  </Spin>
</template>
<script>
import vehicle from '@/pages/claimDemage/tools/ModelVehicle.vue';
import SelectWeiXiuGongDan from '@/pages/claimDemage/tools/SelectWeiXiuGongDan.vue';
import { getPartType } from '@/api/dictionary/index';
import Selectzhusunjian from '@/pages/claimDemage/tools/vehicle.vue';
import Selectguzhangxianxiang from "../../BasicData/ClaimApplication/Selectguzhangxianxiang";
import SelectClaimApplication from "./SelectClaimApplication";
import  Fault from "./Fault";
import { quySP}  from '@/api/claim/dealer/ClaimApplication/index';
import { isFormEmpty } from '@/utils/index';
import Peijianhuanxiajianlist from '@/pages/claimDemage/tools/vehicle.vue';
import {newSave} from '@/api/claim/dealer/QualityInformationManagement_DLR/QualityInformationFeedback/index';
import moment from "moment";
import KeepCar from '@/pages/claimDemage/tools/KeepCar.vue';
import { copyUpdateData } from '@/utils/index';
import { dictionary } from '@/utils/dictMixin';
export default {
  mixins: [dictionary],
  // 弹出层
  components: {
    SelectWeiXiuGongDan,
    Selectzhusunjian,
    Selectguzhangxianxiang,
    SelectClaimApplication,
    Peijianhuanxiajianlist,
    Fault,
    KeepCar,
    vehicle
  },
  data() {
    return {
      loading: false,
      collapse: false,
      infoId: null,
      columns: this.creatHeader(),
      columns2: this.creatHeader2(),
      columns3: this.creatHeader3(),
      // topFilterInit: this.topFilterInitFun(),
      // fetchApi: getUser,
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      formList: this.createFormList(),
      saveData: null,
      weixiugongdan: false,
      zhusunjian:false,
      guzhangxianxiangdaima:false,
      application:false,
      peijianhuanxiajianlistaddflag:false,
      fault:false,
      KeepCarShow: false,
      visible: false
    };
  },
  async created() {
    this.loading = true;
    await this.chuqi();
    this.loading = false;
  },
  methods: {
    async chuqi() {
      console.log("进来了")
      // const res1 = await getPartType({type: 5561});
      // if (res1.resultCode == 200) {
      //   this.formList.find(x => x.fieldName == 'reportStatus').initialValue = 55611001;
      //   this.formList.find(x => x.fieldName == 'reportStatus').itemList = res1.data.map(y => ({
      //     text: y.codeCnDesc,
      //     value: y.codeId
      //   }));
      // }
      // const res3 = await getPartType( {type:5500});
      // if (res3.resultCode == 200) {
      //   this.formList.find(x => x.fieldName == 'isKeep').initialValue = 55001002;
      //   this.formList.find(x => x.fieldName == 'isKeep').itemList = res3.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
      // }
    },
    //提交
    async submit() {
      this.$refs.formPanel1.SUBMIT_FORM();
      let arr1 = [];
      this.$refs.table2.$refs.pageTable.list.map(x => {
        delete  x.partId;
        arr1.push(x);
      });
      console.log(arr1);

      let arr2 = [];
      this.$refs.table1.$refs.pageTable.list.map(x => {
        delete  x.faultId;
        arr2.push(x);
      });
      console.log(arr2);
      let fileList = [];
      this.saveData.fileList.map((x) => {
        fileList.push({ title: x.name, fileUrl: x.url });
      });

      this.saveData.fileList = fileList;
      //故障
      this.saveData.faultList = arr2;
      //换下件
      this.saveData.partList = arr1;
      this.saveData.reportStatus = 55611002;

      //保存前格式化时间类型
      //销售日期
      if(this.saveData.roNo){
        this.saveData.saleDate = moment(this.saveData.saleDate).format('YYYY-MM-DD HH:mm:ss');
        //保修起始日期
        this.saveData.repairBeginDate = moment(this.saveData.repairBeginDate).format('YYYY-MM-DD HH:mm:ss');
        //维修开始时间
        this.saveData.serviceBeginDate = moment(this.saveData.serviceBeginDate).format('YYYY-MM-DD HH:mm:ss');
        //维修结束时间
        this.saveData.serviceEndDate = moment(this.saveData.serviceEndDate).format('YYYY-MM-DD HH:mm:ss');
        //自费配件销售日期
        // this.saveData.selfSdate = moment(this.saveData.selfSdate).format('YYYY-MM-DD HH:mm:ss');
        //生产日期
        this.saveData.prodDate = moment(this.saveData.prodDate).format('YYYY-MM-DD HH:mm:ss');
      }
      this.saveData.cmsClaimId = this.cmsClaimId
      this.saveData.partId = this.partId;
      this.saveData.faultId = this.faultId;
      this.saveData.labourAmount = this.labourAmount;
      this.saveData.partAmount = this.partAmount;
      this.saveData.modelId = this.modelId;
      this.saveData.modelCode = this.modelCode;
      this.saveData.isDeleted = this.isDeleted;


      if(this.saveData.isKeep==55001001){
        this.$confirm('是否确定留车无误?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(async() => {
            this.loading = true;
            let res = await newSave(this.saveData);
            if (res.resultCode === 200) {
              this.$emit('save');
              return this.$notify.success({title: '提示信息', message: '保存成功'});
            } else {
              this.loading = false;
              // this.$notify.error({title: '提示信息', message: res.errMsg || '保存失败!'});
              // this.$emit('save');
            }
          })
          .catch(() => {});
      }else{
        this.loading = true;
        let res = await newSave(this.saveData);

        if (res.resultCode === 200) {
          this.$emit('save');
          return this.$notify.success({ title: '提示信息', message: '保存成功' });
        } else {
          this.loading = false;
          // this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
          // this.closeDialog();
        }
        this.loading = false;
      }

    },
    async cancels(){
      this.formList.find(item => item.fieldName === 'roNo').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'partCode').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'partName').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'faultCode').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'faultName').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'cmsClaimInfo').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'cmsClaimProcess').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'cmsClaimResult').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'useEvn').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'keepCar').rules[0].required = false;
      this.$refs.formPanel1.SUBMIT_FORM();
      let arr1 = [];
      this.$refs.table2.$refs.pageTable.list.map(x => {
        delete  x.partId;
        arr1.push(x);
      });
      console.log(arr1);

      let arr2 = [];
      this.$refs.table1.$refs.pageTable.list.map(x => {
        delete  x.faultId;
        arr2.push(x);
      });
      console.log(arr2);
      let fileList = [];
      this.saveData.fileList.map((x) => {
        fileList.push({ title: x.name, fileUrl: x.url });
      });

      this.saveData.fileList = fileList;
      //故障
      this.saveData.faultList = arr2;
      //换下件
      this.saveData.partList = arr1;

      //判断是保存还是提交 默认0 提交1
      this.saveData.reportStatus = 55611004;
      this.saveData.faultIds = this.faultIds;
      this.saveData.partIds = this.partIds;
      this.saveData.fileIds = this.fileIds;
      this.saveData.partId = this.partId; //主损件id
      this.saveData.supCode = this.supCode; //供应商Code
      this.saveData.modelId= this.modelId; //车型id
      this.saveData.modelCode = this.modelCode ; //车型Code
      this.saveData.faultId = this.faultId; //故障现象主键
      this.saveData.cmsClaimId = this.cmsClaimId ;
      //保存前格式化时间类型
      //销售日期
      if(this.saveData.roNo){
        this.saveData.saleDate = moment(this.saveData.saleDate).format('YYYY-MM-DD HH:mm:ss');
        //保修起始日期
        this.saveData.repairBeginDate = moment(this.saveData.repairBeginDate).format('YYYY-MM-DD HH:mm:ss');
        //维修开始时间
        this.saveData.serviceBeginDate = moment(this.saveData.serviceBeginDate).format('YYYY-MM-DD HH:mm:ss');
        //维修结束时间
        this.saveData.serviceEndDate = moment(this.saveData.serviceEndDate).format('YYYY-MM-DD HH:mm:ss');
        //自费配件销售日期
        // this.saveData.selfSdate = moment(this.saveData.selfSdate).format('YYYY-MM-DD HH:mm:ss');
        //生产日期
        this.saveData.prodDate = moment(this.saveData.prodDate).format('YYYY-MM-DD HH:mm:ss');
      }
      this.newVar = copyUpdateData(this.newVar,this.saveData);
      if(this.saveData != null){
        this.loading = true;
        let res = await newSave(this.newVar);
        if (res.resultCode === 200) {
          this.$emit('save');
          return this.$notify.success({ title: '提示信息', message: '保存成功' });
        } else {
          this.loading = false;
          this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
          // this.closeDialog();
        }
        this.loading = false;
      }

    },
    //保存
    async saveDialog() {
      this.formList.find(item => item.fieldName === 'roNo').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'partCode').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'partName').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'faultCode').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'faultName').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'cmsClaimInfo').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'cmsClaimProcess').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'cmsClaimResult').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'useEvn').rules[0].required = false;
      this.formList.find(item => item.fieldName === 'keepCar').rules[0].required = false;
      this.$refs.formPanel1.SUBMIT_FORM();
      let arr1 = [];
      this.$refs.table2.$refs.pageTable.list.map(x => {
        delete  x.partId;
        arr1.push(x);
      });
      console.log(arr1);

      let arr2 = [];
      this.$refs.table1.$refs.pageTable.list.map(x => {
        delete  x.faultId;
        arr2.push(x);
      });
      console.log(arr2);
      let fileList = [];
      this.saveData.fileList.map((x) => {
        fileList.push({ title: x.name, fileUrl: x.url });
      });

      this.saveData.fileList = fileList;
      //故障
      this.saveData.faultList = arr2;
      //换下件
      this.saveData.partList = arr1;


      //保存前格式化时间类型
      //销售日期
      if(this.saveData.roNo){
        this.saveData.saleDate = moment(this.saveData.saleDate).format('YYYY-MM-DD HH:mm:ss');
        //保修起始日期
        this.saveData.repairBeginDate = moment(this.saveData.repairBeginDate).format('YYYY-MM-DD HH:mm:ss');
        //维修开始时间
        this.saveData.serviceBeginDate = moment(this.saveData.serviceBeginDate).format('YYYY-MM-DD HH:mm:ss');
        //维修结束时间
        this.saveData.serviceEndDate = moment(this.saveData.serviceEndDate).format('YYYY-MM-DD HH:mm:ss');
        //自费配件销售日期
        // this.saveData.selfSdate = moment(this.saveData.selfSdate).format('YYYY-MM-DD HH:mm:ss');
        //生产日期
        this.saveData.prodDate = moment(this.saveData.prodDate).format('YYYY-MM-DD HH:mm:ss');
      }
      this.saveData.cmsClaimId = this.cmsClaimId
      this.saveData.partId = this.partId;
      this.saveData.faultId = this.faultId;
      this.saveData.labourAmount = this.labourAmount;
      this.saveData.partAmount = this.partAmount;
      this.saveData.modelId = this.modelId;
      this.saveData.modelCode = this.modelCode;
      this.saveData.isDeleted = this.isDeleted;
      this.loading = true;
      let res = await newSave(this.saveData);

      if (res.resultCode === 200) {
        this.$emit('save');
        return this.$notify.success({ title: '提示信息', message: '保存成功' });
      } else {
        this.loading = false;
        this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
        // this.closeDialog();
      }
      this.loading = false;
    },
    faultAdd() {
      this.fault = true;
    },
    faultSave(val) {
      let falg = true;
      this.$refs.table1.$refs.pageTable.list.map(x => {
        for(let i in val){
          if(val[i].faultCode == x.faultCode){
            falg = false;
            this.$notify.error({ title: '提示信息', message: '故障码'+x.faultCode+'重复' });
          }
        }

      });
      if(falg) {
        this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(val);
      }
      this.fault = false;
    },
    faultClose() {
      this.fault = false;
    },
    KeepCarShowFn() {
      this.KeepCarShow = true;
    },
    KeepCarSave(obj) {
      this.formList.find(x => x.fieldName == 'keepCar').initialValue = obj[0].keepCar;
      this.KeepCarShow = false;
    },
    KeepCarClose() {
      this.KeepCarShow = false;
    },
    chexingClose()
    {
      this.visible = false;
    },
    delsFun(data) {
      this.$refs.table2.$refs.pageTable.EXECUTE_DELETE([data]);
    },
    //配件换下件列表
    peijianhuanxiajianadd() {
      this.peijianhuanxiajianlistaddflag = true;
    },
    //配件换下件
    peijianhuanxiajianClose() {
      this.peijianhuanxiajianlistaddflag = false;
    },
    peijianhuanxiajianSave(val) {
      let falg = true ;
      this.$refs.table2.$refs.pageTable.list.map(x => {
        for(let i in val){
          let node = val[i];
          if(node.partCode == x.partCode){
            falg = false;
            this.$notify.error({ title: '提示信息', message: '配件选择重复' });
          }
        }
      });
      if(falg){
        this.$refs.table2.$refs.pageTable.EXECUTE_INSERT(val);
      }
      this.peijianhuanxiajianlistaddflag = false;
    },
    async getAuthListByauthNo(id) {
      let res = await quySP({ id: id });
      let data = res.data;
      this.formList.find(x => x.fieldName == 'partCode').initialValue = data.partCode;
      this.formList.find(x => x.fieldName == 'partCode').disabled = true;
      this.formList.find(x => x.fieldName == 'partName').initialValue = data.partName;
      this.partId = data.partId;
      this.formList.find(x => x.fieldName == 'sysCode1').initialValue = data.sysCode1;
      this.formList.find(x => x.fieldName == 'sysName1').initialValue = data.sysName1;
      this.formList.find(x => x.fieldName == 'sysCode2').initialValue = data.sysCode2;
      this.formList.find(x => x.fieldName == 'sysName2').initialValue = data.sysName2;
      this.formList.find(x => x.fieldName == 'sysCode3').initialValue = data.sysCode3;
      this.formList.find(x => x.fieldName == 'sysName3').initialValue = data.sysName3;
      this.formList.find(x => x.fieldName == 'sysCode4').initialValue = data.sysCode4;
      this.formList.find(x => x.fieldName == 'sysName4').initialValue = data.sysName4;
      this.formList.find(x => x.fieldName == 'faultCode').initialValue =data.faultCode;
      this.formList.find(x => x.fieldName == 'faultCode').disabled =true;
      this.formList.find(x => x.fieldName == 'faultName').initialValue =data.faultName;
      this.formList.find(x => x.fieldName == 'roNo').initialValue = data.roNo;
      this.formList.find(x => x.fieldName == 'vin').initialValue = data.vin;
      this.formList.find(x => x.fieldName == 'modelName').initialValue = data.modelName;
      this.formList.find(x => x.fieldName == 'saleDate').initialValue = data.saleDate!=null?moment(data.saleDate).format('YYYY-MM-DD'):null;
      this.formList.find(x => x.fieldName == 'serviceBeginDate').initialValue = data.serviceBeginDate;
      this.formList.find(x => x.fieldName == 'serviceEndDate').initialValue = data.serviceEndDate;
      this.formList.find(x => x.fieldName == 'prodDate').initialValue = data.prodDate!=null?moment(data.prodDate).format('YYYY-MM-DD'):null;
      this.formList.find(x => x.fieldName == 'driveMile').initialValue = data.driveMile;


      this.modelCode = data.modelCode;
      this.modelId = data.modelId;
      this.faultId = data.faId;
      let records2 = data.partList;
      if (isFormEmpty(records2)) {
        records2 = [];
      }
      this.$refs.table2.$refs.pageTable.EXECUTE_DELETE(this.$refs.table2.$refs.pageTable.list);
      this.$refs.table2.$refs.pageTable.EXECUTE_INSERT(records2);
    },
    selectApplicationCode(){
      this.application = true;
    },
    selectpartCode() {
      this.zhusunjian = true;
    },
    selectRono() {
      this.weixiugongdan = true;
    },
    chooseOrderNo() {
      this.visible = true;
    },
    selectfaultCode() {
      this.guzhangxianxiangdaima = true;
    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
      console.log(val);
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //取消操作
    closeDialog() {
      this.$emit('close', {visible: false, data: this.selectedRows, type: 'close'});
    },
    //维修工单
    weixiugongdanClose() {
      this.weixiugongdan = false;
    },
    guzhangxianxiangdaimanClose() {
      this.guzhangxianxiangdaima = false;
    },
    applicationClose(){
      this.application = false;
    },
    delsFunXj(data) {
      this.$refs.table1.$refs.pageTable.EXECUTE_DELETE([data]);
    },
    applicationSave(obj){
      this.formList.find(x => x.fieldName == 'cmsClaimNo').initialValue = obj[0].claimNo;
      this.cmsClaimId = obj[0].claimId;
      this.getAuthListByauthNo(this.cmsClaimId);
      this.application = false;
    },
    guzhangxianxiangdaimaSave(obj) {
      this.formList.find(x => x.fieldName == 'sysCode1').initialValue = obj[0].sysCode1;
      this.formList.find(x => x.fieldName == 'sysName1').initialValue = obj[0].sysName1;
      this.formList.find(x => x.fieldName == 'sysCode2').initialValue = obj[0].sysCode2;
      this.formList.find(x => x.fieldName == 'sysName2').initialValue = obj[0].sysName2;
      this.formList.find(x => x.fieldName == 'sysCode3').initialValue = obj[0].sysCode3;
      this.formList.find(x => x.fieldName == 'sysName3').initialValue = obj[0].sysName3;
      this.formList.find(x => x.fieldName == 'sysCode4').initialValue = obj[0].sysCode4;
      this.formList.find(x => x.fieldName == 'sysName4').initialValue = obj[0].sysName4;
      this.formList.find(x => x.fieldName == 'faultCode').initialValue = obj[0].faultCode;
      this.formList.find(x => x.fieldName == 'faultName').initialValue = obj[0].faultName;
      this.faultId = obj[0].faultId;
      this.guzhangxianxiangdaima = false;

    },
    //主损件
    zhusunjianClose() {
      this.zhusunjian = false;
    },
    zhusunjianSave(obj) {
      this.formList.find(x => x.fieldName == 'partCode').initialValue = obj[0].partCode;
      this.formList.find(x => x.fieldName == 'partName').initialValue = obj[0].partName;
      this.partId = obj[0].partId;
      this.zhusunjian = false;
    },
    weixiugongdanSave(obj) {
      // this.formList.find(x => x.fieldName == 'claimNo').initialValue = obj[0].claimNo;
      this.formList.find(x => x.fieldName == 'roNo').initialValue = obj[0].roNo;
      this.formList.find(x => x.fieldName == 'vin').initialValue = obj[0].vin;
      this.formList.find(x => x.fieldName == 'modelName').initialValue = obj[0].modelName;
      this.formList.find(x => x.fieldName == 'saleDate').initialValue = obj[0].saleDate!=null?moment(obj[0].saleDate).format('YYYY-MM-DD'):null;
      this.formList.find(x => x.fieldName == 'serviceBeginDate').initialValue = obj[0].serviceBeginDate;
      this.formList.find(x => x.fieldName == 'serviceEndDate').initialValue = obj[0].serviceEndDate;
      this.formList.find(x => x.fieldName == 'prodDate').initialValue = obj[0].prodDate!=null?moment(obj[0].prodDate).format('YYYY-MM-DD'):null;
      this.formList.find(x => x.fieldName == 'driveMile').initialValue = obj[0].driveMile;


      this.modelCode = obj[0].modelCode;
      this.modelId = obj[0].modelId;
      this.weixiugongdan = false;

      // 设置带出的数据为置灰不可修改
      this.formList.find(x => x.fieldName == 'vin').disabled=true;
      this.formList.find(x => x.fieldName == 'driveMile').disabled=true;
      this.formList.find(x => x.fieldName == 'saleDate').disabled=true;
      this.formList.find(x => x.fieldName == 'prodDate').disabled=true;
      this.formList.find(x => x.fieldName == 'serviceBeginDate').disabled=true;
      this.formList.find(x => x.fieldName == 'serviceEndDate').disabled=true;
      this.formList.find(x => x.fieldName == 'modelName').disabled=true;
    },
    // 车型
    chexingsave(obj) {
      this.formList.find(x => x.fieldName == 'modelName').initialValue = obj[0].modelName;
      this.modelCode = obj[0].modelCode;
      this.modelId = obj[0].modelId;
      this.visible = false;
    },
    //质量信息
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '质量报告单号',
          fieldName: 'reportNo',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '维修工单号',
          fieldName: 'roNo',
          placeholder: '请输入标题名称...',
          rules: [{ required: false, message: '请输入标题名称', trigger: 'blur' }],
          readonly: true,
          unitRender: p => {
            return (
              <div>
              <multiuse-button icon="el-icon-search" onClick={() => this.selectRono()} />
            </div>
          );
          }
        },
        {
          type: 'SELECT',
          label: '质量报告状态',
          fieldName: 'reportStatus',
          placeholder: '请输入标题名称...',
          disabled: true, // 只读
          initialValue:55611001,
          itemList: this.createDictList('5561'),
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          readonly: false,// 只读
          disabled: false // 置会
        },
        {
          type: 'DATE',
          label: '生产日期',
          fieldName: 'prodDate',
          rules: [{ required: true, message: '请输入生产日期', trigger: 'blur' }],
          readonly: false,// 只读
          disabled: false // 置会
        },
        {
          type: 'SELECT',
          label: '索赔方式',
          fieldName: 'claimType',
          placeholder: '请输入...',
          rules: [{ required: true, message: '请输入索赔方式', trigger: 'blur' }],
          itemList:  [{text:'售前',value:1},{text:'售后',value:2}],
          change: val => {
            if (val == 1) {
              this.formList.map(y => {
                if (y.fieldName == 'saleDate') {
                  y.rules[0].required = false;
                }
              })
            } else {
              this.formList.map(y => {
                if (y.fieldName == 'saleDate') {
                  y.rules[0].required = true;
                }
              })
            }
          }
        },
        {
          type: 'DATE',
          label: '销售日期',
          fieldName: 'saleDate',
          readonly: false,// 只读
          rules: [{ required: false, message: '请输入销售日期', trigger: 'blur' }],
          disabled: false // 置会
        },
        {
          type: 'DATE',
          label: '维修开始时间',
          fieldName: 'serviceBeginDate',
          valueFormat:'yyyy-MM-DD HH:mm:ss',
          readonly: false,// 只读
          disabled: false // 置会
        },
        {
          type: 'DATE',
          label: '维修结束时间',
          fieldName: 'serviceEndDate',
          valueFormat:'yyyy-MM-DD HH:mm:ss',
          readonly: false,// 只读
          disabled: false // 置会
        },
        {
          type: 'INPUT',
          label: '行驶里程',
          fieldName: 'driveMile',
          rules: [{ required: true, message: '请输入行驶里程', trigger: 'blur' }],
          readonly: false,// 只读
          disabled: false // 置会
        },
        {
          type: 'INPUT',
          label: '车型名称',
          fieldName: 'modelName',
          readonly: true,// 只读
          disabled: false, // 置会
          unitRender: p => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.chooseOrderNo()} />
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: '制单人',
          fieldName: 'reporter',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '联系方式',
          fieldName: 'phone',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '主损件',
          fieldName: 'partCode',
          placeholder: '请输入数量...',
          rules: [{ required: true, message: '请输入主损件', trigger: 'blur' }],
          readonly: true,// 只读
          unitRender: p => {
            return (
              <div>
              <multiuse-button icon="el-icon-search" onClick={() => this.selectpartCode()} />
            </div>
          );
          }
        },
        {
          type: 'INPUT',
          label: '主损件名称',
          fieldName: 'partName',
          readonly: true,// 只读
          disabled: true, // 置会
          rules: [{ required: true, message: '请输入主损件名称', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '索赔单号',
          fieldName: 'cmsClaimNo',
          readonly: true,// 只读
         // rules: [{ required: true, message: '请输入索赔单号', trigger: 'blur' }],
          unitRender: p => {
            return (
              <div>
              <multiuse-button icon="el-icon-search" onClick={() => this.selectApplicationCode()} />
            </div>
          );
          }
        },
        {
          type: 'INPUT',
          label: '故障现象代码',
          fieldName: 'faultCode',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          rules: [{ required: true, message: '请输入故障现象代码', trigger: 'blur' }],
          unitRender: p => {
            return (
              <div>
              <multiuse-button icon="el-icon-search" onClick={() => this.selectfaultCode()} />
            </div>
          );
          }
        },
        {
          type: 'INPUT',
          label: '故障现象描述',
          fieldName: 'faultName',
          readonly: true,// 只读
          disabled: true, // 置会
          rules: [{ required: true, message: '请输入故障现象代码', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '一级代码',
          fieldName: 'sysCode1',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '一级名称',
          fieldName: 'sysName1',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '二级代码',
          fieldName: 'sysCode2',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '二级名称',
          fieldName: 'sysName2',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '三级代码',
          fieldName: 'sysCode3',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '三级名称',
          fieldName: 'sysName3',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '故障代码',
          fieldName: 'sysCode4',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '故障名称',
          fieldName: 'sysName4',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'SELECT',
          label: '是否留车',
          fieldName: 'isKeep',
          placeholder: '请输入...',
          itemList:  this.createDictList(5500),
          initialValue:55001002,
          change: val => {
            if (val == 55001001) {
              this.formList.map(y => {
                if (y.fieldName == 'keepCar') {
                  y.disabled = false;
                  y.rules[0].required = true;
                }
              })
            } else {
              this.formList.map(y => {
                if (y.fieldName == 'keepCar') {
                  y.disabled = true;
                  y.initialValue = '';
                  y.rules[0].required = false;
                }
              })
            }
          }
        },
        {
          type: 'INPUT',
          label: '留车单号',
          fieldName: 'keepCar',
          placeholder: '请输入数量...',
          disabled: true, // 置会
          rules:[{ required: false, message: '请输入留车单号', trigger: 'blur' }],
          unitRender: p => {
            return (
              <div>
              <multiuse-button icon="el-icon-search" onClick={() => this.KeepCarShowFn()} />
            </div>
          );
          }
        },
        {
          type: 'INPUT',
          label: '案例主题',
          fieldName: 'caseMain',
          placeholder: '请输入...'
        },
        {
          type: 'TEXT_AREA',
          label: '故障描述',
          fieldName: 'cmsClaimInfo',
          selfCols: 3,// 元素占据几行
          rows: 3,
          rules: [{ required: true, message: '请输入故障描述', trigger: 'blur' }]

        },
        {
          type: 'TEXT_AREA',
          label: '维修经过',
          fieldName: 'cmsClaimProcess',
          selfCols: 3,// 元素占据几行
          rows: 3,
          rules: [{ required: true, message: '请输入维修经过', trigger: 'blur' }]

        },
        {
          type: 'TEXT_AREA',
          label: '维修结果',
          fieldName: 'cmsClaimResult',
          selfCols: 3,// 元素占据几行
          rows: 3,
          rules: [{ required: true, message: '请输入维修结果', trigger: 'blur' }]
        },
        {
          type: 'TEXT_AREA',
          label: '建议意见',
          fieldName: 'suggestion',
          selfCols: 3,// 元素占据几行
          rows: 3
        },
        {
          type: 'TEXT_AREA',
          label: '使用环境',
          fieldName: 'useEvn',
          selfCols: 3,// 元素占据几行
          rows: 3,
          rules: [{ required: true, message: '请输入使用环境', trigger: 'blur' }]
        },
        {
          type: 'UPLOAD_FILE',
          label: '上传文件',
          fieldName: 'fileList',
          placeholder: '上传文件...',
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 100,
            tipText: '（支持PDF、RAR、JPG格式）',
            max:1024*100
          }
        }
      ];
    },
    //故障码列表
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: props => {
            return (
              <div style="text-align:center">
                <multiuse-button type="text" onClick={() => this.delsFunXj(props.row)}>
                  删除
                </multiuse-button>
            </div>
          );
          }
        },
        {title: '诊断仪检测故障码', dataIndex: 'faultCode', sorter: true},
        {title: '故障码描述', dataIndex: 'faultName', sorter: true},
      ];
    },
    //配件列表
    creatHeader2() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: props => {
            return (
              <div style="text-align:center">
                <multiuse-button type="text" onClick={() => this.delsFun(props.row)}>
                  删除
                </multiuse-button>
              </div>
            );
          }
        },
        { title: '配件代码', dataIndex: 'partCode', sorter: true },
        { title: '配件名称', dataIndex: 'partName', sorter: true },
        { title: '单位', dataIndex: 'partUnit', sorter: true },
        { title: '数量', dataIndex: 'partCount', sorter: true ,editable: true,
          defaultEditable: true,
          showOverflowTooltip: true,
          editType: 'number',
          editRequired: true,
          editValidator:(val, row, callback) => {
            this.$refs.table2.$refs.pageTable.list.map((x) => {
              if (row.partCode == x.partCode) {
                this.number = x.partCount
              }
            });
           if(row.partCount==0){
              this.$notify.error({ title: '提示信息', message: '换下件最小数量为1' });
              row.partCount = 1
            }
          }
        }
      ];
    },
    //历史审核记录
    creatHeader3() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {title: '操作人', dataIndex: 'checkBy', sorter: true},
        {title: '操作时间', dataIndex: 'checkAt', sorter: true},
        {title: '操作类型', dataIndex: 'checkStatus', sorter: true},
        {title: '操作备注', dataIndex: 'checkRemarks', sorter: true}
      ];
    },


  }
};
</script>

<style lang="less" scoped></style>
